package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.WkspMaterialList;
import com.ruoyi.mes.service.IWkspMaterialListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领料清单Controller
 * 
 * @author ruoyi
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/mes/pickingList")
public class WkspMaterialListController extends BaseController
{
    @Autowired
    private IWkspMaterialListService wkspMaterialListService;

    /**
     * 查询领料清单列表
     */
    @PreAuthorize("@ss.hasPermi('mes:pickingList:list')")
    @GetMapping("/list")
    public TableDataInfo list(WkspMaterialList wkspMaterialList)
    {
        startPage();
        List<WkspMaterialList> list = wkspMaterialListService.selectWkspMaterialListList(wkspMaterialList);
        return getDataTable(list);
    }

    /**
     * 导出领料清单列表
     */
    @PreAuthorize("@ss.hasPermi('mes:pickingList:export')")
    @Log(title = "领料清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WkspMaterialList wkspMaterialList)
    {
        List<WkspMaterialList> list = wkspMaterialListService.selectWkspMaterialListList(wkspMaterialList);
        ExcelUtil<WkspMaterialList> util = new ExcelUtil<WkspMaterialList>(WkspMaterialList.class);
        util.exportExcel(response, list, "领料清单数据");
    }

    /**
     * 获取领料清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:pickingList:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wkspMaterialListService.selectWkspMaterialListById(id));
    }

    /**
     * 新增领料清单
     */
    @PreAuthorize("@ss.hasPermi('mes:pickingList:add')")
    @Log(title = "领料清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WkspMaterialList wkspMaterialList)
    {
        return toAjax(wkspMaterialListService.insertWkspMaterialList(wkspMaterialList));
    }

    /**
     * 修改领料清单
     */
    @PreAuthorize("@ss.hasPermi('mes:pickingList:edit')")
    @Log(title = "领料清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WkspMaterialList wkspMaterialList)
    {
        return toAjax(wkspMaterialListService.updateWkspMaterialList(wkspMaterialList));
    }

    /**
     * 删除领料清单
     */
    @PreAuthorize("@ss.hasPermi('mes:pickingList:remove')")
    @Log(title = "领料清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wkspMaterialListService.deleteWkspMaterialListByIds(ids));
    }
}
